//
//  KLSGCategoryCollectionViewCell.m
//  KaoLaShiGuangFM
//
//  Created by lanou3g on 15/10/29.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "KLSGCategoryCollectionViewCell.h"

@implementation KLSGCategoryCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.imageView = [[UIImageView alloc] init];
    }
    return self;
}
//
//- (void)subView
//{
//    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
//    self.imageView.backgroundColor = [UIColor grayColor];
//    [self addSubview:self.imageView];
//    
//    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 30)];
//    self.titleLabel.center = CGPointMake(CGRectGetMidX(self.imageView.frame), CGRectGetMidY(self.imageView.frame));
//    self.titleLabel.textAlignment = NSTextAlignmentCenter;
//    self.titleLabel.textColor = [UIColor whiteColor];
//    [self.imageView addSubview:self.titleLabel];
//}

- (void)setImage:(UIImage *)image
{
    CGFloat height = (kScreenWidth / 3 - 10) / image.size.width * image.size.height;
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
    self.imageView.frame = CGRectMake(0, 0, (kScreenWidth / 3 - 10), height);
    self.imageView.image = image;
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.imageView];
    self.height = height;
    
    NSArray *views = self.imageView.subviews;
    for (UIView *subView in views) {
            [subView removeFromSuperview];
    }
    
    UIView *view  = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _imageView.frame.size.width, _imageView.frame.size.height)];
    view.backgroundColor = [UIColor colorWithRed:150 / 255.0 green:120 / 255.0 blue:80 / 255.0 alpha:0.3];
    [_imageView addSubview:view];
    
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.frame = CGRectMake((self.imageView.frame.size.width - 100) / 2, (self.imageView.frame.size.height - 30) / 2, 100, 30);
    [self addSubview:self.titleLabel];
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
    }
    return _titleLabel;
}

@end
